package com.asset.dto;

import com.asset.pojo.User;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 11725
 */
@Data
public class UserDto {
    /** 用户编号 */
    private Long id;

    /** 用户名 */
    private String username;

    /** 姓名 */
    private String name;

    /** 部门名称 */
    private Long depaId;

    /** 账户状态 */
    private Integer status;

    /** 性别 */
    private Integer gender;

    /** 手机号 */
    private String phone;

    /** 角色名称列表 */
    private List<String> roleList;

    public UserDto() {}

    public UserDto(User user) {
        this.id = user.getId();
        this.username = user.getUsername();
        this.name = user.getName();
        this.depaId = user.getDepaId();
        this.status = user.getStatus();
        this.gender = user.getGender();
        this.phone = user.getPhone();
        this.roleList = new ArrayList<>();
        for (GrantedAuthority authority : user.getRoleList()) {
            this.roleList.add(authority.getAuthority());
        }
    }
}
